show: Handle keys of any type, and set an error if key doesn't exist
authorColin Walters <walters@verbum.org>
Fri, 27 Sep 2013 16:55:07 +0000 (12:55 -0400)
committerColin Walters <walters@verbum.org>
Fri, 27 Sep 2013 16:57:01 +0000 (12:57 -0400)
Previously we were just handling strings, and silently doing nothing
if the key didn't exist, which is pretty broken.

src/ostree/ot-builtin-show.c

index 859c3d149970a021d2733fdd3b70ab95b03e09b2..de54535a38e019bed1fc6f64a8f8c93cdd1e1af4 100644 (file)
@@ -107,7 +107,7 @@ do_print_metadata_key (OstreeRepo     *repo,
                        GError        **error)
 {
   gboolean ret = FALSE;
-  const char *value;
+  gs_unref_variant GVariant *value = NULL;
   gs_unref_variant GVariant *commit = NULL;
   gs_unref_variant GVariant *metadata = NULL;
 
@@ -132,10 +132,15 @@ do_print_metadata_key (OstreeRepo     *repo,
         }
     }
   
-  if (!g_variant_lookup (metadata, key, "&s", &value))
-    goto out;
+  value = g_variant_lookup_value (metadata, key, NULL);
+  if (!value)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                   "No such metadata key '%s'", key);
+      goto out;
+    }
 
-  g_print ("%s\n", value);
+  ot_dump_variant (value);
 
   ret = TRUE;
  out: